import { SocketMsg } from "../engine/socketserver/socket/SocketMsg";
import fs = require("fs")
import { Logger } from "../engine/utils/Logger";
const path = require("path")

export class ZoneModel {

    public static Redis_Key: string = "serverlist";

    public static ZoneInfoStatus = {
        Normal: 1,  //正常
        WeiHu: 2, //维护
        NoOpen: 3, //不开放
        Full: 4, //满注册
    }

    public server_id: number; //
    public server_index: number;
    public server_ip: string;   //ip
    public server_port: number; //端口
    public server_name: string;  //服务器名字
    public server_status: number; //服务器状态  1:正常 2：维护 3:没开放 4:满注册
    public server_type: number; //1推荐 2:火爆
    public android_switch: number; //1:开启，0:关闭
    public ios_switch: number; //1:开启，0:关闭

    public static zoneModelList: Array<ZoneModel> = [];

    public static nowZone:ZoneModel;

    public static init() {
        let configPath: string = path.resolve() + "/config/serverlist.json"
        Logger.log("serverlist====", configPath);
        let data: Buffer = fs.readFileSync(configPath);
        let objList: Array<object> = JSON.parse(data.toString());
        this.zoneModelList = [];
        for (let i = 0; i < objList.length; i++) {
            let obj: object = objList[i];
            let model: ZoneModel = new ZoneModel();
            model.server_id = obj["id"];
            model.server_index = obj["index"];
            model.server_ip = obj["ip"];
            model.server_name = obj["name"];
            model.server_port = obj["port"]
            model.server_status = obj["status"];
            model.server_type = obj["server_type"]
            model.android_switch = obj["android_switch"];
            model.ios_switch = obj["ios_switch"];
            this.zoneModelList.push(model);
        }
    }

    public static getZone(id: number) {
        for (let i = 0; this.zoneModelList.length; i++) {
            let zone:ZoneModel = this.zoneModelList[i];
            if(zone.server_id == id){
                return zone;
            }
        }
    }

}